namespace Skymate.Commands
{
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing.Design;
    using System.Linq;
    using System.Windows.Forms;
    using System.Windows.Forms.Design;

    public class LightColorsEditor : UITypeEditor
    {
        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        {
            return UITypeEditorEditStyle.Modal;
        }

        public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value)
        {

            IWindowsFormsEditorService edSvc =

                (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

            if (edSvc == null)
            {
                return value;
            }

            // 可以打开任何特定的对话框
            var colors = value as List<LightColor>;

            var dialog = new LightColorStateDialog(colors);
            if (dialog.ShowDialog().Equals(DialogResult.OK))
            {
                return dialog.LightColorStates.OrderBy(c => c.Index).Select(c => c.LightColor)
                    .ToList();
            }

            return value;
        }
    }
}